<?php
// script to check at what time of the day data is becoming available 
// from eoddata


set_include_path(get_include_path(). PATH_SEPARATOR. 'inc/');
require_once 'inc/globals.secret.php';
function __autoload($class_name) {
  require_once $class_name.'.class.php';
}

function readTimeDir($dir) {
  global $eoddatadir;
  $arr=array();
  $i=0;
  if ($handle = opendir($eoddatadir."/".$dir)) {
    while (false !== ($file = readdir($handle))) {
      if (!is_dir($file)) {
        $arr[$i]['name']=$file;
        $lines=file($eoddatadir."/".$dir."/".$file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
        $arr[$i++]['lines']=sizeof($lines);
      }
    }
    closedir($handle);
  }
  return $arr;
}

function searchArr($arr, $name) {
  foreach ($arr as $data) {
    if ($data['name'] == $name) {
      return $data['lines'];
    }
  }
  return false;
}


chdir($eoddatadir);

$timedirs=array();
if ($handle = opendir($eoddatadir)) {
  while (false !== ($file = readdir($handle))) {
    if (is_dir($file) & $file!="." & $file!=".." & $file!="splits") {
      $timedirs[]=$file;
    }
  }
  closedir($handle);
}

sort($timedirs);

$i=0;
$arr=array();
foreach ($timedirs as $dir) {
  $arr[$i]['dirname'] = $dir;
  $arr[$i++]['contents'] = readTimeDir($dir);
}

for ($i=1; $i<sizeof($arr); $i++) {
  foreach ($arr[$i]['contents'] as $file) {
    $lines = searchArr($arr[$i-1]['contents'], $file['name']);
    if (!$lines) {
      echo $arr[$i]['dirname']." : new file : ".$file['name']."\n";
    } elseif ($lines != $file['lines']) {
      echo $arr[$i]['dirname']." : new filesize : ".$lines." -> ".$file['lines']." ".$file['name']."\n";
    } else {
      echo $arr[$i]['dirname']." no change\n";
    }
  }
}

//print_r($arr);


?>
